function f_check_slave_status()
{   #检查复制状态, MGR状态
    declare delay is_delay is_mgr mgr_count _mysql_slave_host fun_name
    fun_name="f_check_slave_status"
    _mysql_slave_host="${1}"
    if [ -z "${_mysql_slave_host}" ]
    then
        f_logging "REMAIND:${fun_name}" "'${mysql_host}:${mysql_port}' 这可能是个单点或者是MGR集群"
        gh_slave=""
        exe_state="${?}"
        is_delay="0"
    else
        __="show slave status"
        ___="Seconds_Behind_Master: "
        exe_state="0"
        is_delay="$(f_exe_sql_in_mysql "${__}\G" "${_mysql_slave_host%:*}" "${mysql_port}" "slaveN"|grep "${___}"|awk '{print $NF}')" || exe_state="${?}"
    fi

    if [ ${exe_state} -ne 0 ]
    then
        __="select count(*) from performance_schema.replication_group_members;"
        is_mgr="$(f_exe_sql_in_mysql "${__}" "${_mysql_slave_host%:*}" "${mysql_port}" "slave")" && exe_state="${?}" || exe_state="${?}"
        if [ ${exe_state} -eq 0 ] && [ ${is_mgr} -gt 0 ]
        then
            __="select count(*) from performance_schema.replication_group_members where MEMBER_STATE = 'ONLINE';"
            mgr_count="$(f_exe_sql_in_mysql "${__}" "${_mysql_slave_host%:*}" "${mysql_port}" "slave")" && exe_state="${?}" || exe_state="${?}"
        fi

        if [ "${is_mgr}x" != "${mgr_count}x" ]
        then
            if [ -n "${_mysql_slave_host}" ]
            then
                f_logging "ERROR:${fun_name}" "获取从节点 '${_mysql_slave_host}' 复制状态失败, 将终止本次操作" "2" "1"
            else
                f_logging "WARN:${fun_name}" "'${mysql_host}:${mysql_port}' 这可能是个单点"
            fi
        else
            f_logging "INFO:${fun_name}" "'${mysql_host}:${mysql_port}' MGR集群状态信息"
            __="select * from performance_schema.replication_group_members;"
            f_exe_sql_in_mysql "${__}" "${_mysql_slave_host%:*}" "${mysql_port}" "slave" || true
            f_logging "INFO:${fun_name}" "'${mysql_host}:${mysql_port}' MGR集群状态信息"
        fi
    elif [ ${exe_state} -eq 0 ] && [ "${is_delay}x" == "NULLx" ]
    then
        f_logging "ERROR:${fun_name}" "从节点 '${_mysql_slave_host}' 复制状态异常" "2" "1"
    elif [ ${exe_state} -eq 0 ] && [ "${is_delay}x" != "0x" ] && [ "$(awk -v t="${slave_mark_sbm}" '{if ($1 <= t){print 1}}' <<< "${is_delay}")x" == "1x" ]
    then
        f_logging "REMAIND:${fun_name}" "从节点 '${_mysql_slave_host}:${is_delay}s' 复制存在延迟, 小于${slave_mark_sbm}s, 本次改表继续"
        return 0
    elif [ ${exe_state} -eq 0 ] && [ "${is_delay}x" != "0x" ]
    then
        if [ "$(awk -v t="${slave_max_sbm}" '{if ($1 <= t){print 1}}' <<< "${is_delay}")x" == "1x" ]
        then #如果延迟小于slave_max_sbm, 就等slave_max_sbm秒, 期间延迟小于slave_mark_sbm这个秒数就继续改表
            for ((delay=0; delay<${slave_max_sbm}; delay++))
            do
                is_delay="$(f_exe_sql_in_mysql "${__}\G" "${_mysql_slave_host%:*}" "${mysql_port}" "slaveN"|grep "${___}"|awk '{print $NF}')" || true
                [ "$(awk -v t="${slave_mark_sbm}" '{if ($1 <= t){print 1}}' <<< "${is_delay}")x" == "1x" ] && break
                sleep 1
            done
        fi

        if [ "$(awk -v t="${slave_mark_sbm}" '{if ($1 <= t){print 1}}' <<< "${is_delay}")x" == "1x" ]
        then
            __="从节点 '${_mysql_slave_host}:${is_delay}s' 复制存在延迟, 经过${slave_max_sbm}s等待后, 延迟小于${slave_mark_sbm}s, 本次改表继续"
            f_logging "REMAIND:${fun_name}" "${__}"
            return 0
        elif [ "${delay}x" == "x" ]
        then
            f_logging "ERROR:${fun_name}" "从节点 '${_mysql_slave_host}:${is_delay}s' 复制存在延迟, 大于${slave_mark_sbm}s 本次改表失败" "2" "1"
        else
            __="从节点 '${_mysql_slave_host}:${is_delay}s' 复制存在延迟, 经过${slave_max_sbm}s等待后, 仍然大于${slave_mark_sbm}s, 本次改表失败"
            f_logging "ERROR:${fun_name}" "${__}" "2" "1"
        fi
    fi
    return 0
}

